<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MyPHPMailer {
    private $mUserName;
    private $mPassword;
    private $mFrom;
    private $mAReplyTo;

    function __construct()
    {
        require_once ('PHPMailer/class.phpmailer.php');
        $mailInfo = unserialize(getOption('mailer'));
        $this->mUserName = $mailInfo['username'];
        $this->mPassword = $mailInfo['password'];
        $this->mFrom = $mailInfo['from'];
        //$this->mAReplyTo = $mailInfo['contact_mail_reply_to'];
        $this->mAReplyTo = array();
    }

    public function config()
    {
        $mail = new PHPMailer();
        $mail->CharSet = 'UTF-8';
        $mail->IsSMTP(); // we are going to use SMTP
        $mail->SMTPAuth = true; // enabled SMTP authentication
        $mail->SMTPSecure = "ssl"; // prefix for secure protocol to connect to the server
        $mail->Host = "smtp.gmail.com"; // setting GMail as our SMTP server
        $mail->Port = 465; // SMTP port to connect to GMail
        $mail->Username = $this->mUserName; // user email address
        $mail->Password = $this->mPassword; // password in GMail

        //$mail->SetFrom($this->mFrom['email'], $this->mFrom['name']); //Who is sending the email
        $mail->SetFrom('support@phienchoviet.com', 'Phiên Chợ Việt'); //Who is sending the email

        foreach ($this->mAReplyTo as $r) {
            $mail->AddReplyTo($r['email'], $r['name']); //email address that receives the response
        }

        $mail->isHTML(true);
        return $mail;
    }
}
?>